const express=require('express');
const path=require('path');
const bodyParser=require('body-parser')
const artTemplate=require('./templateEngine/artTemplate');

const cookieParser = require('cookie-parser')

const verifyLoginMiddleware = require('./middleware/verifyLogin.js');
//首页
const indexRoute=require('./routes/index');
const frontRoute=require('./routes/front');


//产品中心
const detailRouter=require('./routes/proDetail');
const frontProRouter=require('./routes/front-pro');


//网站基本信息
const frontBaseInfoRouter=require('./routes/front-baseInfo');
const hfRouter=require('./routes/hf.js');
const aboutRouter=require('./routes/about.js');
const contactRouter=require('./routes/contact.js');

//新闻中心
const newsRouter = require('./routes/news.js');
const backRouter = require('./routes/back.js');
/*和后台相关，但是不需要登录的操作*/
const commonRouter = require('./routes/common.js');
const frnewsRouter = require('./routes/frnews.js');


//工厂照片和在线留言
//引入后台工厂照片路由
const factoryPicRouter = require("./routes/factoryPic.js");
const frFactoryPicRouter = require("./routes/frfactoryPic.js");
const onlineMsgRouter = require("./routes/onlineMsg.js")
const frOnlineMsgRouter = require("./routes/frOnlineMsg.js")


const app=express();
const port=3000;



/* cookie 处理 */
app.use(cookieParser())

//使用模板引擎
artTemplate(app);


app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

//设置网站的静态资源信息
//如localhost:3000/backend/css/font.css
app.use(express.static('public'));


app.use('/admin',indexRoute);
app.use(frontRoute);

app.use('/front',frontProRouter);


//产品中心
app.use('/admin/product',detailRouter);


//网站基本信息
app.use(frontBaseInfoRouter);
app.use('/admin/website',hfRouter);
app.use('/admin/about',aboutRouter);
app.use('/admin',contactRouter);


//新闻中心
let verifyFn = verifyLoginMiddleware.verifyLogin;

/*下面的路由是不要做登录检测*/
app.use('/admin', commonRouter);
app.use('/front', frnewsRouter);

// 这里面是登录的业务代码，不需做登录检测的

app.use('/admin', verifyFn, indexRoute);
app.use('/admin/news', verifyFn, newsRouter);
app.use('/admin', verifyFn, backRouter);

//工厂照片和在线留言
app.use("/admin", factoryPicRouter);
app.use("/admin", onlineMsgRouter)
app.use(frFactoryPicRouter);

app.use(frOnlineMsgRouter);



app.listen(port,()=>{
    console.log(`project listening at http//localhost:${port}`);
})